package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.QrtzSimpropTriggers;
import io.mybatis.example.springboot.service.QrtzSimpropTriggersService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * QRTZ_SIMPROP_TRIGGERS - 同步机制的行锁表
 *
 * @author mkj
 */
@RestController
@RequestMapping("qrtzSimpropTriggerses")
public class QrtzSimpropTriggersController {

  @Autowired
  private QrtzSimpropTriggersService qrtzSimpropTriggersService;

  @PostMapping
  public DataResponse<QrtzSimpropTriggersDO> save(@RequestBody QrtzSimpropTriggersDO qrtzSimpropTriggers) {
    return DataResponse.ok(qrtzSimpropTriggersService.save( qrtzSimpropTriggers));
  }

  @GetMapping
  public RowsResponse<QrtzSimpropTriggersDO> findList(@RequestBody QrtzSimpropTriggersDO qrtzSimpropTriggers) {
    return RowsResponse.ok(qrtzSimpropTriggersService.findList( qrtzSimpropTriggers));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<QrtzSimpropTriggersDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzSimpropTriggersService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<QrtzSimpropTriggersDO> update(@PathVariable("id") Long id, @RequestBody QrtzSimpropTriggersDO qrtzSimpropTriggers) {
    qrtzSimpropTriggers.setId(id);
    return DataResponse.ok(qrtzSimpropTriggersService.update( qrtzSimpropTriggers));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzSimpropTriggersService.deleteById(id) == 1);
  }

}
